package com.zzzs.threaddemo;

import lombok.SneakyThrows;

/**
 * @author zhu_shuai
 * @since 9/2
 */
public class Demo01_Join {
    @SneakyThrows
    public static void main(String[] args) {
        MyRunable c = new MyRunable("C");
        Thread thread2 = new Thread(c);
        MyRunable b = new MyRunable("B");
        Thread thread1 = new Thread(b);
        MyRunable a = new MyRunable("A");
        Thread thread = new Thread(a);
        thread.start();
        thread.join();
        thread1.start();
        thread1.join();
        thread2.start();
        thread2.join();


    }

    static class MyRunable implements Runnable{

        private String name;
        private Thread thread;
        public MyRunable(String name) {
            this.name = name;
        }

        public MyRunable(String name, Thread thread) {
            this.name = name;
            this.thread = thread;
        }

        @SneakyThrows
        @Override
        public void run() {
            if (thread != null){
                thread.join();
            }
            System.out.printf("thread - %s %n", this.name);

        }
    }
}
